<?php
/*****[BEGIN]******************************************
 [ Base:     oPanel Functions                  v1.5.0 ]
 ******************************************************/
function size_hum_read($size){
  $i=0;
  $iec = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
  while (($size/1024)>1) {
   $size=$size/1024;
   $i++;
  }
  return substr($size,0,strpos($size,'.')+4).$iec[$i];
}
function HomeLength($dir) {
$ExPath = explode("/", $dir);
$length = Count($ExPath)-2;
return $length;
}
function XMLFileImg($line) {
 $x = new xml();
 $source = file_get_contents('includes/filetypes.xml');
 $x->fetch($source);
$tpe = strrchr($line,'.');
if(isset($tpe) && $tpe == "") { return('images/i-regular.gif'); }
$type = strtoupper(str_replace('.','',$tpe));
$ext = $x->data->FILETYPES[0]->EXTENTIONS[0];
if(isset($ext->$type) && $current = $ext->$type) { $imgsrc = $current[0]->_attr->IMG;
} else { $imgsrc = 'images/i-regular.gif'; } return $imgsrc;}
/*****[END]********************************************
 [ Base:     oPanel Functions                  v1.5.0 ]
 ******************************************************/
session_start();
include('functions.php');
$home = $_SESSION["home"];
/*****[BEGIN]******************************************
 [ Base:     oPanel Template Functions         v1.0.1 ]
 ******************************************************/
function CurrnetFol($path, $imgsrc) {
$htmlTemplate = <<<HTM
<table width=100%><tr><td><a href="$path"><img src="$imgsrc" border=0></a></td>
	<td>
	 / $path (Current Folder)
	</td></tr>
	
HTM;
return $htmlTemplate;
}
function DirlistTemplate($link, $link2, $imgsrc, $filename, $size, $perm, $style) {
if($size != '' || $size == '0') { $filesize = size_hum_read($size); } else { $filesize = '&nbsp;'; }
if($perm != '') { $permission = substr(sprintf('%o', $perm), -4); } else { $permission = '&npsp;'; }
if(!isset($style)) { $style = ''; }
if(is_dir($filename)) { $targ = 'filemain'; } else { $targ = 'infofr'; }
$filename = basename($filename);
$tpe = strrchr($filename,'.');
$htmlTemplate = <<<HTM
<tr$style><td width=50 align=left><a href="$link" target=$targ ><img border=0 src="$imgsrc"></a></td><td align=left><a href="$link2" target=infofr$style>
$filename</a></td><td>$filesize</td><td>$permission</td></tr>
HTM;
return $htmlTemplate;
}
function UpOneLevel($link) {
$htmlTemplate = <<<HTM
<tr><td><a href="$link" target="filemain"><img src="images/i-directory.gif" border=0></a></td>
	<td>
	<a href="$link" target="filemain">
	<b>Up one level</b></a></td></tr>
HTM;
return $htmlTemplate;
}
/*****[END]********************************************
 [ Base:     oPanel Template Functions         v1.0.1 ]
 ******************************************************/
?>
<html>
<head>
<title>oPanel V<?php echo $ver; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet"href="style.css">
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript" src="includes/js.php"></script>
</head>
<body<?php if(isset($_SESSION["new"])) { echo ' onLoad="ChangePass()">'; } else { echo '>'; }
if ($_SESSION["pass"] != check($_SESSION["user"])) { secure(); exit; } 
elseif(!isset($_SESSION["pass"])) { secure(); exit; } ?>
<script type="text/javascript">
parent.trashframe.location="http://<?php echo $_SERVER["HTTP_HOST"]; echo dirname("$_SERVER[SCRIPT_NAME]"); ?>/trash.php";
</script>
<div id="topnav"><p align="right"><?php if($_SESSION["power"] == 'Administrator') { echo '<a href="admin.php" target="_blank">Launch Admin Control Panel</a> - '; } ?><a href="javascript:ChangePass()">Change Password</a> - <a href="login.php?logout=true">Logout - <img src=images/close.jpg border=0></a></p></div>
<table align=center width=100% cellspacing="0">
  <tr> 
    <td> 
<div align="center"><font class="big">File Manager</font></div>    </td>
<td>&nbsp;</td></tr>
  <tr> 
    <td colspan="2"> 
      <hr />
      <div align="center"><font class="med">Click on a folder icon to navigate.<br>
	Click on a name to view its properties.</font><br></div>    </td></tr>
</table>
<?php
/*****[BEGIN]******************************************
 [ Base:     oPanel Move Function              v2.0.0 ]
 ******************************************************/
 if(isset($_GET['move']) && $_GET['move'] == 'true') {
$old = $_GET['old'];
if(isset($_GET['new'])) {
$new = $_GET['new'];
} else {
$new = $home;
}
if(isset($_GET['file'])) {
$file = $_GET['file'];
}
$ExPath = explode(DIRECTORY_SEPARATOR, $new);
$ExCpath = Count($ExPath)-1;
for ($i=0; $i < $ExCpath; $i++) {
if ($i == 0){
$Fpath = $ExPath[0];
}else{
$Fpath = $Fpath.DIRECTORY_SEPARATOR.$ExPath[$i];
} if ($i < HomeLength($home)) {
} else {
if(isset($_GET['file'])) {
if(!isset($SXpath)) {
$SXpath = "<a href='list.php?move=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."&file=".$file."'>".$ExPath[$i]."</a> / ";
} else {
$SXpath = $SXpath."<a href='list.php?move=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."&file=".$file."'>".$ExPath[$i]."</a> / ";
}
} else {
if(!isset($SXpath)) {
$SXpath = "<a href='list.php?move=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."'>".$ExPath[$i]."</a> / ";
} else {
$SXpath = $SXpath."<a href='list.php?move=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."'>".$ExPath[$i]."</a> / ";
} } } }
echo CurrnetFol($SXpath, 'images/blank.gif');
if (dirname(realpath($new)) != dirname(realpath($home))) {
$ExPath = explode(DIRECTORY_SEPARATOR, $new);
$ExCpath = Count($ExPath)-2;
for ($i=0; $i < $ExCpath; $i++) {
if ($i == 0){
$Fpath = $ExPath[0];
}else{
$Fpath = $Fpath.DIRECTORY_SEPARATOR.$ExPath[$i];
}
}
$path = $Fpath;
if(isset($file)) {
$link = "list.php?move=true&new=".$path.DIRECTORY_SEPARATOR."&old=".$old."&file=".$file."";
echo UpOneLevel($link);
} else {
$link = "list.php?move=true&new=".$path.DIRECTORY_SEPARATOR."&old=".$old."";
echo UpOneLevel($link);
}
}
$lines = scandir($new);
foreach ($lines as $line_num => $line) {
if ($line != ".") {
 if ($line != "..") {
   $bob = "$new$line";
  if (is_dir($bob)) {
   if(isset($file)) {
   $link1 = "list.php?move=true&new=$bob".DIRECTORY_SEPARATOR."&old=$old&file=$file";
   $imgsrc ="images/i-directory.gif";
   $link2 = "move.php?new=$bob".DIRECTORY_SEPARATOR."&old=$old&file=$file";
   $perm = fileperms("$bob");
echo DirlistTemplate($link1, $link2, $imgsrc, $bob, '', $perm, '');
} else {
   $link1 = "list.php?move=true&new=$bob".DIRECTORY_SEPARATOR."&old=$old";
   $imgsrc = "images/i-directory.gif";
   $link2 = "move.php?new=$bob".DIRECTORY_SEPARATOR."&old=$old";
   $perm = fileperms("$bob");
echo DirlistTemplate($link1, $link2, $imgsrc, $bob, '', $perm, '');
} } } } } exit; } // end isset()
/*****[END]********************************************
 [ Base:     oPanel Move Function              v2.0.0 ]
 ******************************************************/
/*****[BEGIN]******************************************
 [ Base:     oPanel Copy Function              v2.0.0 ]
 ******************************************************/
if(isset($_GET['copy']) && $_GET['copy'] == 'true') {
$old = $_GET['old'];
if(isset($_GET['new'])) {
$new = $_GET['new'];
} else {
$new = $home;
}
if(isset($_GET['file'])) {
$file = $_GET['file'];
}
$ExPath = explode(DIRECTORY_SEPARATOR, $new);
$ExCpath = Count($ExPath)-1;
for ($i=0; $i < $ExCpath; $i++) {
if ($i == 0){
$Fpath = $ExPath[0];
}else{
$Fpath = $Fpath.DIRECTORY_SEPARATOR.$ExPath[$i];
}
if ($i < HomeLength($home)) {
} else {
if(isset($_GET['file'])) {
if(!isset($SXpath)) {
$SXpath = "<a href='list.php?copy=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."&file=".$file."'>".$ExPath[$i]."</a> / ";
} else {
$SXpath = $SXpath."<a href='list.php?copy=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."&file=".$file."'>".$ExPath[$i]."</a> / ";
}
} else {
if(!isset($SXpath)) {
$SXpath = "<a href='list.php?copy=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."'>".$ExPath[$i]."</a> ".DIRECTORY_SEPARATOR;
} else {
$SXpath = $SXpath."<a href='list.php?copy=true&new=".$Fpath.DIRECTORY_SEPARATOR."&old=".$old."'>".$ExPath[$i]."</a> ".DIRECTORY_SEPARATOR;
} } } }
echo CurrnetFol($SXpath, 'images/blank.gif');
if (dirname(realpath($new)) != dirname(realpath($home))) {
$ExPath = explode(DIRECTORY_SEPARATOR, $new);
$ExCpath = Count($ExPath)-2;
for ($i=0; $i < $ExCpath; $i++) {
if ($i == 0){
$Fpath = $ExPath[0];
}else{
$Fpath = $Fpath.DIRECTORY_SEPARATOR.$ExPath[$i];
} }
$path = $Fpath;
if(isset($file)) {
$link = "list.php?copy=true&new=$path/&old=$old&file=$file"; 
echo UpOneLevel($link);
} else {
$link = "list.php?copy=true&new=$path/&old=$old"; 
echo UpOneLevel($link);
}
}
$lines = scandir($new);
foreach ($lines as $line_num => $line) {
if ($line != ".") {
 if ($line != "..") {
   $bob = "$new$line";
  if (is_dir($bob)) {
   if(isset($file)) {
   $link1 = "list.php?copy=true&new=$bob/&old=$old&file=$file";
   $imgsrc ="images/i-directory.gif";
   $link2 = "copy.php?new=$bob/&old=$old&file=$file";
   $perm = fileperms("$bob");
echo DirlistTemplate($link1, $link2, $imgsrc, $bob, '', $perm, '');
} else {
   $link1 = "list.php?copy=true&new=$bob/&old=$old";
   $imgsrc = "images/i-directory.gif";
   $link2 = "copy.php?new=$bob/&old=$old";
   $perm = fileperms("$bob");
echo DirlistTemplate($link1, $link2, $imgsrc, $bob, '', $perm, '');
} } } } }
exit; }
/*****[END]********************************************
 [ Base:     oPanel Copy Function              v2.0.0 ]
 ******************************************************/
if (!isset($_GET['dir'])) {
$dir = $home;
} else {
$dir = $_GET['dir']; // lets find the file we are talking about
}
$folder = realpath("$dir"); // returns the proper dir()
$ExPath = explode("/", $dir);
$ExCpath = count($ExPath)-1;
$ExTpath = $ExCpath-1;
if($ExTpath < HomeLength($home)) { $dir = $home; $ExPath = explode("/", $home); $ExCpath = Count($ExPath)-1; }
for ($i=0; $i < $ExCpath; $i++) {
if ($i == 0){
$Fpath = $ExPath[0];
}else{
$Fpath = $Fpath."/".$ExPath[$i];
}
if ($i < HomeLength($home)) {
} else {
if(!isset($SXpath)) {
$SXpath = "<a href='list.php?dir=".$Fpath."/'>".$ExPath[$i]."</a> / ";
} else {
$SXpath = $SXpath."<a href='list.php?dir=".$Fpath."/'>".$ExPath[$i]."</a> / ";
} } }
echo CurrnetFol($SXpath, 'images/i-directory.gif');
if($createDir == true || $_SESSION['power'] == 'Administrator') {
echo <<<LOL
	 <tr><td><img src="images/i-directory.gif" width="16" height="16" border=0></td>
	<td>
	<a href="makedir.php?dir={$dir}" target="infofr">
	<b>Create New Folder</b></td></tr>
LOL;
}
if($upload == true || $_SESSION["power"] == 'Administrator') {
echo <<<LOL
<tr><td height="44"><img src="images/up.gif" border=0></td>
	<td height="44">
	<a href="upload.php?dir={$dir}" target="filemain">
	<b>Upload a file</b></td></tr>
LOL;
}
if (dirname(realpath($dir)) != dirname(realpath($home))) {
$ExPath = explode("/", $dir);
$ExCpath = Count($ExPath)-2;
for ($i=0; $i < $ExCpath; $i++) {
if ($i == 0){
$Fpath = $ExPath[0];
}else{
$Fpath = $Fpath."/".$ExPath[$i];
}
}
$path = $Fpath;
$path = 'list.php?dir='.$path.'/';
echo UpOneLevel($path);
}
$lines = scandir($dir);
foreach ($lines as $line_num => $line) {
if ($line != ".") {
 if ($line != "..") {
   $file = "$dir$line";
  if (is_dir($file)) {
     if ($_SESSION["power"] != 'Administrator' && $line == "downloads" || $_SESSION["power"] != 'Administrator' && $line == "oPanel") { } else {
    $link1 = "list.php?dir=$file/";
   $imgsrc = "images/i-directory.gif";
   $link2 = "select.php?dir=$file/";
   $perm = fileperms("$file");
echo DirlistTemplate($link1, $link2, $imgsrc, $file, '', $perm, '');
} } } } }
if($createFile == true || $_SESSION['power'] == 'Administrator') {
echo <<<LOL
	 <tr><td><img src="images/i-regular.gif" border=0></td>
	<td>
	<a href="mkfile.php?dir={$dir}" target="infofr">
	<b>Create New File</b></td></tr>
LOL;
}
$lines = scandir($dir);
foreach ($lines as $line_num => $line) {
if ($line != ".") {
 if ($line != "..") {
   $file = "$dir$line";
$type = strrchr($line,'.');
  if (!(is_dir($file))) {
$ExPath = explode(".", $line);
$ExCpath = Count($ExPath)-1;
for ($i=0; $i < $ExCpath; $i++) {
if ($i == 0){
$Fpath = $ExPath[0];
}else{
$Fpath = $Fpath."/".$ExPath[$i];
}
}
$imgsrc = XMLFileImg($line);
$file = "$dir$line";
if($type == ".zip") {
$name= $Fpath;
	$link = "select.php?dir=$dir&zip=true&name=$name";
	$size = filesize("$file");
	$perm = fileperms($file);
echo DirlistTemplate($link, $link, $imgsrc, $file, $size, $perm, '');
} elseif (is_writable($file)) {
    	$link = "select.php?dir=$dir&file=$line";
	$size = filesize("$file");
	$perm = fileperms($file);
echo DirlistTemplate($link, $link, $imgsrc, $file, $size, $perm, '');
} else {
	$link = "select.php?dir=$dir&file=$line";
	$size = filesize("$file");
	$perm = fileperms($file);
	$style = ' style="color: red"';
echo DirlistTemplate($link, $link, $imgsrc, $file, $size, $perm, $style);
} } } } } ?>
</table>
<div style="position: absolute; width: 264px; height: 17px; z-index: 1; vertical-align: baseline; left:10px" id="credits">
oPanel V<?php echo $ver; ?> by <a href="http://olliespage.net/" target ="_blank">OlliesPage.net</a></div>
<div style="position: absolute; width: 500px; height: 17px; z-index: 1; vertical-align: baseline; right: 19px; text-align: right" id="BetaTesters">
BETA testers: <?php echo $BETAtesters; ?></div>
</body>
</html>